/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.fee.core.service.processor.check;

import cn.hutool.core.lang.Assert;
import info.peigen.hotpot.business.account.core.domain.account.Account;
import info.peigen.hotpot.business.account.core.service.processor.base.AbstractAccountServiceProcessor;
import info.peigen.hotpot.business.fee.facade.command.order.FeeOrder;
import info.peigen.hotpot.common.core.result.ResultCode;
import info.peigen.hotpot.common.service.base.exception.BusinessException;
import info.peigen.hotpot.common.service.base.processor.Processor;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import org.noear.solon.annotation.Component;


/**
 * <b>(CheckCalculateFeeProcessor)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/6/3
 */
@Component
public class CheckCalculateFeeProcessor extends AbstractAccountServiceProcessor implements Processor {
    @Override
    public Integer level() {
        return 3;
    }

    @Override
    public void execute(ProcessorServiceContext serviceContext) {
        FeeOrder order   = (FeeOrder) serviceContext.getOrder();
        Account  account = accountRepository.active(order.getCustomerId());
        Assert.notNull(account, () -> new BusinessException(ResultCode.FAILURE, "客户账户不存在"));

        Assert.notNull(order.getPartnerId(), () -> new BusinessException(ResultCode.FAILURE, "未指定合作伙伴，不能命中收费规则"));
    }

}